<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的预约 - 医疗预约系统</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <style>
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }
        .header h1 {
            color: #2c3e50;
            margin: 0;
        }
        .logout-btn {
            background-color: #e74c3c;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
        }
        .logout-btn:hover {
            background-color: #c0392b;
        }
        .profile-container {
            display: flex;
            gap: 30px;
        }
        .sidebar {
            width: 250px;
            background: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .user-info {
            text-align: center;
            margin-bottom: 20px;
        }
        .avatar {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            object-fit: cover;
            max-width: 100%;
            max-height: 100%;
            margin-bottom: 15px;
            border: 3px solid #3498db;
        }
        .menu-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .menu-item {
            margin-bottom: 5px;
        }
        .menu-link {
            display: block;
            padding: 12px 15px;
            color: #555;
            text-decoration: none;
            border-radius: 5px;
            transition: all 0.3s;
        }
        .menu-link:hover {
            background-color: #f5f5f5;
            color: #3498db;
        }
        .menu-link.active {
            background-color: #3498db;
            color: white;
        }
        .content {
            flex: 1;
            background: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .content-header {
            margin-bottom: 25px;
        }
        .content-header h2 {
            color: #2c3e50;
            margin: 0;
        }
        .appointment-card {
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            transition: box-shadow 0.3s ease;
        }
        .appointment-card:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        .appointment-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        .appointment-number {
            font-size: 18px;
            font-weight: bold;
            color: #2c3e50;
        }
        .status-badge {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: bold;
        }
        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }
        .status-paid {
            background-color: #d4edda;
            color: #155724;
        }
        .status-completed {
            background-color: #cce5ff;
            color: #004085;
        }
        .status-cancelled {
            background-color: #f8d7da;
            color: #721c24;
        }
        .appointment-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-bottom: 15px;
        }
        .detail-item {
            color: #7f8c8d;
        }
        .detail-item strong {
            color: #2c3e50;
        }
        .appointment-actions {
            text-align: right;
        }
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            margin-left: 10px;
        }
        .btn-primary {
            background-color: #3498db;
            color: white;
        }
        .btn-primary:hover {
            background-color: #2980b9;
        }
        .btn-success {
            background-color: #27ae60;
            color: white;
        }
        .btn-success:hover {
            background-color: #229954;
        }
        .btn-danger {
            background-color: #e74c3c;
            color: white;
        }
        .btn-danger:hover {
            background-color: #c0392b;
        }
        .btn-secondary {
            background-color: #95a5a6;
            color: white;
        }
        .btn-secondary:hover {
            background-color: #7f8c8d;
        }
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #7f8c8d;
        }
        .empty-state h3 {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>医疗预约系统 - 个人中心</h1>
            <a href="auth/logout" class="logout-btn">退出登录</a>
        </div>

        <div class="profile-container">
            <!-- 侧边菜单 -->
            <div class="sidebar">
                <div class="user-info">
                    <img src="statics/images/adminHead/${loginUser != null && loginUser.headpic != null ? loginUser.headpic : 'default.png'}" alt="用户头像" class="avatar">
                    <h3>${loginUser != null ? loginUser.username : '用户'}</h3>
                    <p>普通用户</p>
                </div>
                <ul class="menu-list">
                    <li class="menu-item"><a href="frontend/profile" class="menu-link">个人信息</a></li>
                    <li class="menu-item"><a href="frontend/my-appointments" class="menu-link active">预约记录</a></li>
                    <li class="menu-item"><a href="frontend/my-reports" class="menu-link">就诊记录</a></li>
                </ul>
            </div>

            <!-- 主要内容 -->
            <div class="content">
                <div class="content-header">
                    <h2>我的预约</h2>
                </div>
            <h2>我的预约</h2>

            <c:choose>
                <c:when test="${not empty appointments}">
                    <c:forEach items="${appointments}" var="appointment">
                        <div class="appointment-card">
                            <div class="appointment-header">
                                <div class="appointment-number">预约号：${appointment.number}</div>
                                <div class="status-badge status-${appointment.status == 0 ? 'pending' : appointment.status == 1 ? 'paid' : appointment.status == 2 ? 'completed' : 'cancelled'}">
                                    <c:choose>
                                        <c:when test="${appointment.status == 0}">待支付</c:when>
                                        <c:when test="${appointment.status == 1}">已支付</c:when>
                                        <c:when test="${appointment.status == 2}">已完成</c:when>
                                        <c:otherwise>已取消</c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                            
                            <div class="appointment-details">
                                <div class="detail-item">
                                    <strong>患者姓名：</strong>${appointment.patientName}
                                </div>
                                <div class="detail-item">
                                    <strong>联系电话：</strong>${appointment.patientPhone}
                                </div>
                                <div class="detail-item">
                                    <strong>医生：</strong>${appointment.visit.doctorName}
                                </div>
                                <div class="detail-item">
                                    <strong>科室：</strong>${appointment.visit.department.deptName}
                                </div>
                                <div class="detail-item">
                                    <strong>医院：</strong>${appointment.visit.department.hospital.hospitalName}
                                </div>
                                <div class="detail-item">
                                    <strong>就诊日期：</strong>${appointment.visit.visitDate}
                                </div>
                                <div class="detail-item">
                                    <strong>就诊时段：</strong>${appointment.visit.timeSlot}
                                </div>
                                <div class="detail-item">
                                    <strong>预约时间：</strong>${appointment.createTimeString}
                                </div>
                            </div>
                            
                            <c:if test="${not empty appointment.symptoms}">
                                <div class="detail-item">
                                    <strong>病情描述：</strong>${appointment.symptoms}
                                </div>
                            </c:if>
                            
                            <div class="appointment-actions">
                                <c:choose>
                                    <c:when test="${appointment.status == 0}">
                                        <a href="frontend/payment?appointmentNo=${appointment.number}" class="btn btn-primary">立即支付</a>
                                        <a href="appointment/cancel?appointmentId=${appointment.appointmentId}" class="btn btn-danger" 
                                           onclick="return confirm('确定要取消这个预约吗？')">取消预约</a>
                                    </c:when>
                                    <c:when test="${appointment.status == 1}">
                                        <span class="btn btn-secondary">已支付</span>
                                        <a href="appointment/cancel?appointmentId=${appointment.appointmentId}" class="btn btn-danger" 
                                           onclick="return confirm('确定要取消这个预约吗？')">取消预约</a>
                                    </c:when>
                                    <c:when test="${appointment.status == 2}">
                                        <span class="btn btn-success">已完成</span>
                                        <a href="report/findById?appointmentId=${appointment.appointmentId}" class="btn btn-primary">查看病单</a>
                                    </c:when>
                                    <c:otherwise>
                                        <span class="btn btn-secondary">已取消</span>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                        </div>
                    </c:forEach>
                </c:when>
                <c:otherwise>
                    <div class="empty-state">
                        <h3>暂无预约记录</h3>
                        <p>您还没有任何预约记录，<a href="frontend/index">立即预约</a></p>
                    </div>
            </c:otherwise>
        </c:choose>
            </div>
        </div>
    </div>
</body>
</html>
